import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import FooterView from '../views/FooterView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // {
    //   path: '/',
    //   redirect: "/home"
    // },
    {
      path: '/',
      name: 'home',
      components:{
        default: HomeView,
        qwe: FooterView
      },
      alias: "/home"
    },
    {
      path: '/news',
      name: 'n',
      component: () => import('../views/NewsView.vue'),
      // 当前路由的导航守卫
      // beforeEnter:(to, from)=>{
        // console.log(to, from);
        // if(from.path === "/join"){
        //   return false;
        // }
      // }
    },
    {
      path: '/newsDetail/:index/:username/:password',
      name: 'nDetail',
      component: () => import('../views/NewsDetailView.vue')
    },
    {
      path: '/join',
      name: 'join',
      component: () => import('../views/JoinView.vue')
    },
    {
      path: '/case',
      name: 'case',
      component: () => import('../views/CaseView.vue'),
      children: [{
        path: "detail/:id",
        name: "cDetail",
        component: () => import('../views/CaseDetailView.vue')
      }]
    },
    {
      path: '/about',
      name: 'about',
      components: {
        default:() => import('../views/AboutView.vue'),
        qwe: FooterView
      }
    }
  ]
})

// 全局的导航守卫
// router.beforeEach((to, from)=>{
//   console.log(to);
//   console.log(from);
//   if(to.path === "/news"){
//     return "/join"
//   }
// })

export default router
